package StackPackage;

import java.util.ArrayList;

/**
 * Created by thoughtworks on 17/7/14.
 */
public class Stack<T>
{
    private ArrayList<T> data;
    public Stack()
    {
        this.data = new ArrayList<T>();
    }

    public void push(T o)
    {
        data.add(o);
    }
    public T pop()
    {
        if(!isEmpty())
        {
            return data.remove(data.size() - 1);
        }
        else
        {
            return null;
        }
    }
    public int size()
    {
        return data.size();
    }
    public boolean isEmpty()
    {
        return data.isEmpty();
    }

    public void printStack()
    {
        for (int i = data.size() - 1; i >= 0; i--) {
            System.out.println(data.get(i));
        }
    }
}
